﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DDD;
using Xunit;

namespace DokiDokiTest {
    public class TestObject {
        [Fact]
        public void Test_New1 () {
            var obj = (DDD.Object)new Node ();

            Assert.Equal (0, obj.UserID);
            Assert.Equal (0, obj.UserObject.Count);
            Assert.Equal (true, obj.IsAnimationEnabled);
            Assert.Equal (true, obj.IsDirty);
            Assert.Equal (0, obj.AnimationClipCount);
        }

        [Fact]
        public void Test_Dirty () {
            var obj = (DDD.Object)new Node ();
            obj.SetDirtyFlag (false);
                
            Assert.Equal (false, obj.IsDirty);
        }

        [Fact]
        public void Test_UniqID () {
            var obj1 = (DDD.Object)new Node ();
            var obj2 = (DDD.Object)new Node ();

            Assert.NotEqual (obj2.UniqueID, obj1.UniqueID);
        }

        [Fact]
        public void Test_UserID () {
            var obj = (DDD.Object)new Node ();
            obj.UserID = 100;

            Assert.Equal (100, obj.UserID);
        }

        [Fact]
        public void Test_GetUserObject () {
            var obj = (DDD.Object)new Node ();
            obj.SetUserObject ("Hello", "World");
            obj.SetUserObject ("Hello", "Good-bye");

            Assert.ReferenceEquals ("Good-bye", obj.GetUserObject ("Hello"));
        }

        [Fact]
        public void Test_IsAnimationEnabled () {
            var obj = (DDD.Object)new Node ();
            obj.SetAnimationEnable (false);

            Assert.Equal (false, obj.IsAnimationEnabled);
        }

        [Fact]
        public void Test_AddAnimation () {
            var clip = new AnimationClip ("Hello world");
            var obj = (DDD.Object)new Node ();
            obj.AddAnimation (clip);

            Assert.Equal (1, obj.AnimationClipCount);
        }

        [Fact]
        public void Test_RemoveAnimation () {
            var clip1 = new AnimationClip ("Hello world, 1");
            var clip2 = new AnimationClip ("Hello world, 2");
            var clip3 = new AnimationClip ("Hello world, 2");
            var obj = (DDD.Object)new Node ();
            obj.AddAnimation (clip1);
            obj.AddAnimation (clip2);
            obj.AddAnimation (clip3);

            Assert.Equal (3, obj.AnimationClipCount);

            obj.RemoveAnimation (clip1);
            Assert.Equal (2, obj.AnimationClipCount);

            obj.RemoveAnimation (clip2);
            Assert.Equal (1, obj.AnimationClipCount);

            obj.RemoveAnimation (clip3);
            Assert.Equal (0, obj.AnimationClipCount);
        }

        [Fact]
        public void Test_GetName () {
            var obj = (DDD.Object)new Node ();

            Assert.Equal ("UserID", DDD.Object.GetName (() => obj.UserID));
        }

        [Fact]
        public void Test_References () {
            var clip1 = new AnimationClip ("Clip 1");
            var clip2 = new AnimationClip ("Clip 2");
            var clip3 = new AnimationClip ("Clip 3");
            var nod = new Node ();
            nod.AddAnimation (clip1);
            nod.AddAnimation (clip2);
            nod.AddAnimation (clip3);

            var objs = nod.References;

            Assert.Equal (3, objs.Count ());
            Assert.Equal (true, objs.All (x => x != null));
        }

        [Fact]
        public void Test_Find () {
            var clip1 = new AnimationClip ("Clip 1");
            var clip2 = new AnimationClip ("Clip 2");
            var clip3 = new AnimationClip ("Clip 3");
            var nod = new Node ();
            nod.AddAnimation (clip1);
            nod.AddAnimation (clip2);
            nod.AddAnimation (clip3);

            clip1.UserID = 101;
            clip2.UserID = 102;
            clip3.UserID = 103;
            nod.UserID = 104;

            Assert.Equal (clip1, nod.Find (101));
            Assert.Equal (clip2, nod.Find (102));
            Assert.Equal (clip3, nod.Find (103));
            Assert.Equal (nod, nod.Find (104));
        }


        [Fact]
        public void Test_Finds () {
            var clip1 = new AnimationClip ("Clip 1");
            var clip2 = new AnimationClip ("Clip 2");
            var clip3 = new AnimationClip ("Clip 3");
            var nod = new Node ();
            nod.AddAnimation (clip1);
            nod.AddAnimation (clip2);
            nod.AddAnimation (clip3);

            clip1.UserID = 101;
            clip2.UserID = 102;
            clip3.UserID = 102;
            nod.UserID = 101;

            var f101 = nod.Finds (101);
            var f102 = nod.Finds (102);

            Assert.Equal (2, f101.Length);
            Assert.Equal (2, f102.Length);
            Assert.Equal (nod, f101[0]);
            Assert.Equal (clip1, f101[1]);
            Assert.Equal (clip2, f102[0]);
            Assert.Equal (clip3, f102[1]);
        }

        [Fact]
        public void Test_Aimate () {
            // Not implemented
        }


        [Fact]
        public void Test_Rase () {
            // Not implemented
        }


    }
}
